package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 查询所有注册用户信息
     * 返回值：PageResult
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") int page,
                                @RequestParam(defaultValue = "10") int pagesize) {
        PageResult pr = manageService.findAllUsers(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 根据id查询用户资料
     */
    @GetMapping("/users/{id}")
    public ResponseEntity findUserById(@PathVariable("id") Long id) {
        UserInfo info = manageService.findUserById(id);
        return ResponseEntity.ok(info);
    }

    /**
     * 根据用户id查询，用户发布的视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "10") int pagesize,
                                 Long uid) {
        PageResult pr = manageService.findVideosByUserId(uid,page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 查询动态详情
     *    请求连接：messages
     *    参数：
     *      page,pagesize,uid,state
     */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "10") int pagesize,
                                 Long uid,
                                 Integer state) {
        PageResult pr = manageService.findMovementByUserId(uid,state,page,pagesize);
        return ResponseEntity.ok(pr);
    }




}
